package com.jyw.business.obstacles.controller;

import com.jyw.business.obstacles.domain.vo.web.*;
import com.jyw.business.obstacles.service.IObsOrderInfoService;
import com.jyw.common.core.controller.BaseController;
import com.jyw.common.core.domain.CommonResult;
import com.jyw.common.core.page.BasePage;
import com.jyw.common.core.page.TableDataInfo;
import com.jyw.common.utils.DateUtils;
import com.jyw.system.domain.dto.BaseTimeDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "首页")
@RestController
@RequestMapping("/obstacles/home")
public class ObsHomeController extends BaseController {

    @Resource
    private IObsOrderInfoService orderInfoService;

    @GetMapping("server")
    @ApiOperation("我的服务台")
    public CommonResult<List<HomeMineServerVO>> mineServer(BaseTimeDto baseTimeDto){
        if (!ObjectUtils.isEmpty(baseTimeDto)) {
            baseTimeDto.setEndDate(DateUtils.toDateLastTime(baseTimeDto.getEndDate()));
        }
        return CommonResult.success(orderInfoService.mineServer(baseTimeDto));
    }

    @GetMapping("fault")
    @ApiOperation("我的工单")
    public CommonResult<List<HomeMineOrderVO>> mineOrder(BaseTimeDto baseTimeDto){
        if (!ObjectUtils.isEmpty(baseTimeDto)) {
            baseTimeDto.setEndDate(DateUtils.toDateLastTime(baseTimeDto.getEndDate()));
        }
        return CommonResult.success(orderInfoService.mineOrder(baseTimeDto));
    }

    @GetMapping("todo")
    @ApiOperation("我的待办事项(报障)")
    public CommonResult<HomeObsToDoVO> todo(){
        return CommonResult.success(orderInfoService.todo());
    }

    @GetMapping("order/source")
    @ApiOperation("报修来源统计(折线图)")
    @ApiImplicitParam(name = "type",value = "类型 1:7天内 2:1个月内 3:近一年",required = true)
    public CommonResult<HomeOrderSourceChartVO> orderSource(String type){
        return CommonResult.success(orderInfoService.homeOrderSource(type));
    }

    @GetMapping("order/source/total")
    @ApiOperation("报修来源统计(总数)")
    public CommonResult<HomeOrderSourceTotalVO> orderSourceTotal(){
        return CommonResult.success(orderInfoService.homeOrderSourceTotal());
    }

    @GetMapping("order/fault/rank")
    @ApiOperation("报修故障分类排名")
    public CommonResult<List<HomeOrderFaultRankVO>> orderFaultRank(BaseTimeDto baseTimeDto){
        return CommonResult.success(orderInfoService.orderFaultRank(baseTimeDto));
    }

    @GetMapping("order/user/rank")
    @ApiOperation("工程师接单数排名")
    public CommonResult<List<HomeUserOrderRankVO>> orderUserRank(BaseTimeDto baseTimeDto){
        return CommonResult.success(orderInfoService.orderUserRank(baseTimeDto));
    }

    @GetMapping("order/warning")
    @ApiOperation("告警消息")
    public TableDataInfo<HomeOrderWarningVO> orderWarning(BasePage page){
        if(!ObjectUtils.isEmpty(page)){
            startPage();
        }
        return getDataTable(orderInfoService.orderWarning());
    }



}
